package com.itheima.service.company;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.company.CompanyDao;
import com.itheima.domain.company.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.ref.PhantomReference;
import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;


    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public PageInfo<Company> findAll(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Company> all = companyDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public void save(Company company) {
        company.setId(UUID.randomUUID().toString());
        companyDao.save(company);
    }

    @Override
    public void update(Company company) {
        companyDao.update(company);
    }

    @Override
    public void delete(String id) {

        companyDao.delete(id);
    }

    @Override
    public Company findById(String id) {

        return companyDao.findById(id);
    }
}
